package com.ruoyi.system.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ReceiptOrderDetail;
import com.ruoyi.system.service.IReceiptOrderDetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库单详情Controller
 * 
 * @author ruoyi
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/wms/detail")
public class ReceiptOrderDetailController extends BaseController
{
    @Autowired
    private IReceiptOrderDetailService receiptOrderDetailService;

    /**
     * 查询入库单详情列表
     */
    @PreAuthorize("@ss.hasPermi('wms:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReceiptOrderDetail receiptOrderDetail)
    {
        startPage();
        List<ReceiptOrderDetail> list = receiptOrderDetailService.selectReceiptOrderDetailList(receiptOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出入库单详情列表
     */
    @PreAuthorize("@ss.hasPermi('wms:detail:export')")
    @Log(title = "入库单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReceiptOrderDetail receiptOrderDetail)
    {
        List<ReceiptOrderDetail> list = receiptOrderDetailService.selectReceiptOrderDetailList(receiptOrderDetail);
        ExcelUtil<ReceiptOrderDetail> util = new ExcelUtil<ReceiptOrderDetail>(ReceiptOrderDetail.class);
        util.exportExcel(response, list, "入库单详情数据");
    }

    /**
     * 获取入库单详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(receiptOrderDetailService.selectReceiptOrderDetailById(id));
    }

    /**
     * 根据入库单Id获取入库单详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:detail:query')")
    @GetMapping(value = "/s/{id}")
    public TableDataInfo getByIdInfo(@PathVariable("id") Long id)
    {
        List<Map<String,Object>> list = receiptOrderDetailService.selectReceiptOrderIdList(id);
        return getDataTable(list);
    }

    /**
     * 新增入库单详情
     */
    @PreAuthorize("@ss.hasPermi('wms:detail:add')")
    @Log(title = "入库单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReceiptOrderDetail receiptOrderDetail)
    {
        return toAjax(receiptOrderDetailService.insertReceiptOrderDetail(receiptOrderDetail));
    }

    /**
     * 修改入库单详情
     */
    @PreAuthorize("@ss.hasPermi('wms:detail:edit')")
    @Log(title = "入库单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReceiptOrderDetail receiptOrderDetail)
    {
        return toAjax(receiptOrderDetailService.updateReceiptOrderDetail(receiptOrderDetail));
    }

    /**
     * 删除入库单详情
     */
    @PreAuthorize("@ss.hasPermi('wms:detail:remove')")
    @Log(title = "入库单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(receiptOrderDetailService.deleteReceiptOrderDetailByIds(ids));
    }

    /**
     * 删除入库单详情
     */
    @PreAuthorize("@ss.hasPermi('wms:detail:remove')")
    @Log(title = "入库单详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/s/{id}")
    public AjaxResult deleteId(@PathVariable Long id)
    {
        return toAjax(receiptOrderDetailService.deleteReceiptOrderDetailById(id));
    }
}
